package br.com.sigupper.daos;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.sigupper.entidades.Categoria;
import br.com.sigupper.util.HibernateUtil;

public class CategoriaDAO {
	private Session sessao;
    private Transaction trans;

    public void addCategoria(Categoria c) {
        this.sessao = HibernateUtil.getSession().getCurrentSession();
        this.trans = sessao.beginTransaction();

        try {
            
            this.sessao.save(c);
            this.trans.commit();
        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            sessao.close();
        }
    }

    public void removeCategoria(Categoria c) {

        try {
            sessao = HibernateUtil.getSession().openSession();
            trans = sessao.beginTransaction();
            sessao.delete(c);
            trans.commit();

        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            sessao.close();
        }
    }
}
